package wn.lizzy.thread.ball;

/**
 * 一个线程就是一个任务，使得小球完成移动，重画，休息等任务。
 * @author cuilijian
 *
 */
public class BallRunnable implements Runnable{

	private Ball ball;
	private BallComponent component;
	public static final int STEPS = 1000;
	public static final int DELAY = 5;
	
	public BallRunnable(Ball ball, BallComponent component){
		this.ball = ball;
		this.component = component;
	}
	@Override
	public void run() {
		try{
			for(int i = 1; i <= STEPS; i++){
				ball.move(component.getBounds());
				component.paintComponent(component.getGraphics());
				Thread.sleep(DELAY);
			}
		}catch (InterruptedException e){
			e.printStackTrace();
		}
		
	}

}
